<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Voro++: v_base.cc Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Voro++
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">v_base.cc</div>  </div>
</div>
<div class="contents">
<a href="v__base_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Voro++, a 3D cell-based Voronoi library</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Author   : Chris H. Rycroft (LBL / UC Berkeley)</span>
<a name="l00004"></a>00004 <span class="comment">// Email    : chr@alum.mit.edu</span>
<a name="l00005"></a>00005 <span class="comment">// Date     : August 30th 2011</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">/** \file v_base.cc</span>
<a name="l00008"></a>00008 <span class="comment"> * \brief Function implementations for the base Voronoi container class. */</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;<a class="code" href="v__base_8hh.html" title="Header file for the base Voronoi container class.">v_base.hh</a>&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;<a class="code" href="config_8hh.html" title="Master configuration file for setting various compile-time options.">config.hh</a>&quot;</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="keyword">namespace </span>voro {
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">/** This function is called during container construction. The routine scans</span>
<a name="l00016"></a>00016 <span class="comment"> * all of the worklists in the wl[] array. For a given worklist of blocks</span>
<a name="l00017"></a>00017 <span class="comment"> * labeled \f$w_1\f$ to \f$w_n\f$, it computes a sequence \f$r_0\f$ to</span>
<a name="l00018"></a>00018 <span class="comment"> * \f$r_n\f$ so that $r_i$ is the minimum distance to all the blocks</span>
<a name="l00019"></a>00019 <span class="comment"> * \f$w_{j}\f$ where \f$j&gt;i\f$ and all blocks outside the worklist. The values</span>
<a name="l00020"></a>00020 <span class="comment"> * of \f$r_n\f$ is calculated first, as the minimum distance to any block in</span>
<a name="l00021"></a>00021 <span class="comment"> * the shell surrounding the worklist. The \f$r_i\f$ are then computed in</span>
<a name="l00022"></a>00022 <span class="comment"> * reverse order by considering the distance to \f$w_{i+1}\f$. */</span>
<a name="l00023"></a><a class="code" href="classvoro_1_1voro__base.html#a74f367e3bcffcd95c800ce9be85c29dc">00023</a> <a class="code" href="classvoro_1_1voro__base.html#a74f367e3bcffcd95c800ce9be85c29dc">voro_base::voro_base</a>(<span class="keywordtype">int</span> nx_,<span class="keywordtype">int</span> ny_,<span class="keywordtype">int</span> nz_,<span class="keywordtype">double</span> boxx_,<span class="keywordtype">double</span> boxy_,<span class="keywordtype">double</span> boxz_) :
<a name="l00024"></a>00024         nx(nx_), ny(ny_), nz(nz_), nxy(nx_*ny_), nxyz(nxy*nz_), boxx(boxx_), boxy(boxy_), boxz(boxz_),
<a name="l00025"></a>00025         xsp(1/boxx_), ysp(1/boxy_), zsp(1/boxz_), mrad(new double[wl_hgridcu*wl_seq_length]) {
<a name="l00026"></a>00026         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> b1=1&lt;&lt;21,b2=1&lt;&lt;22,b3=1&lt;&lt;24,b4=1&lt;&lt;25,b5=1&lt;&lt;27,b6=1&lt;&lt;28;
<a name="l00027"></a>00027         <span class="keyword">const</span> <span class="keywordtype">double</span> xstep=<a class="code" href="classvoro_1_1voro__base.html#ac8986e621bd70cf5113e231cb8694d37">boxx</a>/wl_fgrid,ystep=<a class="code" href="classvoro_1_1voro__base.html#a3ad6b0eefbdff03e92d30f5035defdd1">boxy</a>/wl_fgrid,zstep=<a class="code" href="classvoro_1_1voro__base.html#afd53f018c9641c8b8066e9429c88a4e0">boxz</a>/wl_fgrid;
<a name="l00028"></a>00028         <span class="keywordtype">int</span> i,j,k,lx,ly,lz,q;
<a name="l00029"></a>00029         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> f,*e=<span class="keyword">const_cast&lt;</span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>*<span class="keyword">&gt;</span> (<a class="code" href="classvoro_1_1voro__base.html#aa6eda2569de04b8baa027db258f97f0d">wl</a>);
<a name="l00030"></a>00030         <span class="keywordtype">double</span> xlo,ylo,zlo,xhi,yhi,zhi,minr,*radp=<a class="code" href="classvoro_1_1voro__base.html#ab59b5feedb35ea611b05d65df1216775">mrad</a>;
<a name="l00031"></a>00031         <span class="keywordflow">for</span>(zlo=0,zhi=zstep,lz=0;lz&lt;wl_hgrid;zlo=zhi,zhi+=zstep,lz++) {
<a name="l00032"></a>00032                 <span class="keywordflow">for</span>(ylo=0,yhi=ystep,ly=0;ly&lt;wl_hgrid;ylo=yhi,yhi+=ystep,ly++) {
<a name="l00033"></a>00033                         <span class="keywordflow">for</span>(xlo=0,xhi=xstep,lx=0;lx&lt;wl_hgrid;xlo=xhi,xhi+=xstep,lx++) {
<a name="l00034"></a>00034                                 minr=large_number;
<a name="l00035"></a>00035                                 <span class="keywordflow">for</span>(q=e[0]+1;q&lt;wl_seq_length;q++) {
<a name="l00036"></a>00036                                         f=e[q];
<a name="l00037"></a>00037                                         i=(f&amp;127)-64;
<a name="l00038"></a>00038                                         j=(f&gt;&gt;7&amp;127)-64;
<a name="l00039"></a>00039                                         k=(f&gt;&gt;14&amp;127)-64;
<a name="l00040"></a>00040                                         <span class="keywordflow">if</span>((f&amp;b2)==b2) {
<a name="l00041"></a>00041                                                 compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i-1,j,k);
<a name="l00042"></a>00042                                                 <span class="keywordflow">if</span>((f&amp;b1)==0) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i+1,j,k);
<a name="l00043"></a>00043                                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span>((f&amp;b1)==b1) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i+1,j,k);
<a name="l00044"></a>00044                                         <span class="keywordflow">if</span>((f&amp;b4)==b4) {
<a name="l00045"></a>00045                                                 compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j-1,k);
<a name="l00046"></a>00046                                                 <span class="keywordflow">if</span>((f&amp;b3)==0) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j+1,k);
<a name="l00047"></a>00047                                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span>((f&amp;b3)==b3) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j+1,k);
<a name="l00048"></a>00048                                         <span class="keywordflow">if</span>((f&amp;b6)==b6) {
<a name="l00049"></a>00049                                                 compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j,k-1);
<a name="l00050"></a>00050                                                 <span class="keywordflow">if</span>((f&amp;b5)==0) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j,k+1);
<a name="l00051"></a>00051                                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span>((f&amp;b5)==b5) compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j,k+1);
<a name="l00052"></a>00052                                 }
<a name="l00053"></a>00053                                 q--;
<a name="l00054"></a>00054                                 <span class="keywordflow">while</span>(q&gt;0) {
<a name="l00055"></a>00055                                         radp[q]=minr;
<a name="l00056"></a>00056                                         f=e[q];
<a name="l00057"></a>00057                                         i=(f&amp;127)-64;
<a name="l00058"></a>00058                                         j=(f&gt;&gt;7&amp;127)-64;
<a name="l00059"></a>00059                                         k=(f&gt;&gt;14&amp;127)-64;
<a name="l00060"></a>00060                                         compute_minimum(minr,xlo,xhi,ylo,yhi,zlo,zhi,i,j,k);
<a name="l00061"></a>00061                                         q--;
<a name="l00062"></a>00062                                 }
<a name="l00063"></a>00063                                 *radp=minr;
<a name="l00064"></a>00064                                 e+=wl_seq_length;
<a name="l00065"></a>00065                                 radp+=wl_seq_length;
<a name="l00066"></a>00066                         }
<a name="l00067"></a>00067                 }
<a name="l00068"></a>00068         }
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 <span class="comment"></span>
<a name="l00071"></a>00071 <span class="comment">/** Computes the minimum distance from a subregion to a given block. If this distance</span>
<a name="l00072"></a>00072 <span class="comment"> * is smaller than the value of minr, then it passes</span>
<a name="l00073"></a>00073 <span class="comment"> * \param[in,out] minr a pointer to the current minimum distance. If the distance</span>
<a name="l00074"></a>00074 <span class="comment"> *                     computed in this function is smaller, then this distance is</span>
<a name="l00075"></a>00075 <span class="comment"> *                     set to the new one.</span>
<a name="l00076"></a>00076 <span class="comment"> * \param[out] (xlo,ylo,zlo) the lower coordinates of the subregion being</span>
<a name="l00077"></a>00077 <span class="comment"> *                           considered.</span>
<a name="l00078"></a>00078 <span class="comment"> * \param[out] (xhi,yhi,zhi) the upper coordinates of the subregion being</span>
<a name="l00079"></a>00079 <span class="comment"> *                           considered.</span>
<a name="l00080"></a>00080 <span class="comment"> * \param[in] (ti,tj,tk) the coordinates of the block. */</span>
<a name="l00081"></a>00081 <span class="keywordtype">void</span> voro_base::compute_minimum(<span class="keywordtype">double</span> &amp;minr,<span class="keywordtype">double</span> &amp;xlo,<span class="keywordtype">double</span> &amp;xhi,<span class="keywordtype">double</span> &amp;ylo,<span class="keywordtype">double</span> &amp;yhi,<span class="keywordtype">double</span> &amp;zlo,<span class="keywordtype">double</span> &amp;zhi,<span class="keywordtype">int</span> ti,<span class="keywordtype">int</span> tj,<span class="keywordtype">int</span> tk) {
<a name="l00082"></a>00082         <span class="keywordtype">double</span> radsq,temp;
<a name="l00083"></a>00083         <span class="keywordflow">if</span>(ti&gt;0) {temp=<a class="code" href="classvoro_1_1voro__base.html#ac8986e621bd70cf5113e231cb8694d37">boxx</a>*ti-xhi;radsq=temp*temp;}
<a name="l00084"></a>00084         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ti&lt;0) {temp=xlo-<a class="code" href="classvoro_1_1voro__base.html#ac8986e621bd70cf5113e231cb8694d37">boxx</a>*(1+ti);radsq=temp*temp;}
<a name="l00085"></a>00085         <span class="keywordflow">else</span> radsq=0;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087         <span class="keywordflow">if</span>(tj&gt;0) {temp=<a class="code" href="classvoro_1_1voro__base.html#a3ad6b0eefbdff03e92d30f5035defdd1">boxy</a>*tj-yhi;radsq+=temp*temp;}
<a name="l00088"></a>00088         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(tj&lt;0) {temp=ylo-<a class="code" href="classvoro_1_1voro__base.html#a3ad6b0eefbdff03e92d30f5035defdd1">boxy</a>*(1+tj);radsq+=temp*temp;}
<a name="l00089"></a>00089 
<a name="l00090"></a>00090         <span class="keywordflow">if</span>(tk&gt;0) {temp=<a class="code" href="classvoro_1_1voro__base.html#afd53f018c9641c8b8066e9429c88a4e0">boxz</a>*tk-zhi;radsq+=temp*temp;}
<a name="l00091"></a>00091         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(tk&lt;0) {temp=zlo-<a class="code" href="classvoro_1_1voro__base.html#afd53f018c9641c8b8066e9429c88a4e0">boxz</a>*(1+tk);radsq+=temp*temp;}
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         <span class="keywordflow">if</span>(radsq&lt;minr) minr=radsq;
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 <span class="comment"></span>
<a name="l00096"></a>00096 <span class="comment">/** Checks to see whether &quot;%n&quot; appears in a format sequence to determine</span>
<a name="l00097"></a>00097 <span class="comment"> * whether neighbor information is required or not.</span>
<a name="l00098"></a>00098 <span class="comment"> * \param[in] format the format string to check.</span>
<a name="l00099"></a>00099 <span class="comment"> * \return True if a &quot;%n&quot; is found, false otherwise. */</span>
<a name="l00100"></a><a class="code" href="classvoro_1_1voro__base.html#a95d9ee6c1610afccf265198ae63b5e88">00100</a> <span class="keywordtype">bool</span> <a class="code" href="classvoro_1_1voro__base.html#a95d9ee6c1610afccf265198ae63b5e88">voro_base::contains_neighbor</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format) {
<a name="l00101"></a>00101         <span class="keywordtype">char</span> *fmp=(<span class="keyword">const_cast&lt;</span><span class="keywordtype">char</span>*<span class="keyword">&gt;</span>(format));
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <span class="comment">// Check to see if &quot;%n&quot; appears in the format sequence</span>
<a name="l00104"></a>00104         <span class="keywordflow">while</span>(*fmp!=0) {
<a name="l00105"></a>00105                 <span class="keywordflow">if</span>(*fmp==<span class="charliteral">&#39;%&#39;</span>) {
<a name="l00106"></a>00106                         fmp++;
<a name="l00107"></a>00107                         <span class="keywordflow">if</span>(*fmp==<span class="charliteral">&#39;n&#39;</span>) <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00108"></a>00108                         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(*fmp==0) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110                 fmp++;
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="preprocessor">#include &quot;<a class="code" href="v__base__wl_8cc.html" title="The table of block worklists that are used during the cell computation.">v_base_wl.cc</a>&quot;</span>
<a name="l00117"></a>00117 
<a name="l00118"></a>00118 }
</pre></div></div>
</div>


<hr class="footer"/><address class="footer"><small>
Generated on Fri Sep 23 2011 22:49:06 for Voro++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
